package com.ophiux.websocket.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

/**
 * @desc:
 * @author: hhl
 * @date：2023/9/27 11:41
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws Exception {
        System.out.println("主线程开始");

        /*CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println("读取文件");
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                    System.out.println("异常");
                }
                System.out.println("读取文件结束。。。。");
            }
        });*/

        /*CompletableFuture.runAsync(() -> {
            System.out.println("读取文件");
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                System.out.println("异常");
            }
            System.out.println("读取文件结束。。。。");
        });*/

        /*CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("读取文件");
            return "读取成功..返回结果....";
        });
        System.out.println("主线程进行中1");
        String s = completableFuture.get();
        System.out.println(s);*/







        System.out.println("主线程进行中");
//        Thread.sleep(4000);
        System.out.println("主线程结束");

    }
}
